package com.jsmy.softapp.net;

import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.jsmy.softapp.MyApp;
import com.jsmy.softapp.bean.AppTJListBean;
import com.jsmy.softapp.bean.AppZLGroupBean;
import com.jsmy.softapp.bean.AppZLListBean;
import com.jsmy.softapp.bean.CustomerBean;
import com.jsmy.softapp.bean.GTKJListBean;
import com.jsmy.softapp.bean.LoginBean;
import com.jsmy.softapp.bean.PlanInfoBean;
import com.jsmy.softapp.bean.RankListBean;
import com.jsmy.softapp.bean.TXLBean;
import com.jsmy.softapp.bean.VersionBean;
import com.jsmy.softapp.bean.YWgtjhBean;
import com.jsmy.softapp.util.CacheDataManager;
import com.jsmy.softapp.util.CheckNetWork;
import com.jsmy.softapp.util.GlideApp;
import com.jsmy.softapp.util.MyLog;

import org.json.JSONObject;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;
import okhttp3.Cache;
import okhttp3.CacheControl;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created with Android Studio.
 * User: wei_cd.
 * Date: 2018/4/16.
 * Time: 10:36.
 * To change for file | settings | file and code templates.
 */

public class NetWork {
    private static final String TAG = "NetWork";

    public static void setImageGlide(Context context, String url, ImageView img) {
        GlideApp.with(context)
                .load(url)
                .dontAnimate()
                .diskCacheStrategy(DiskCacheStrategy.RESOURCE)
                .placeholder(img.getDrawable())
                .into(img);
    }

    //网络请求回调
    public interface CallListener {
        void onSuccess(String type, String code, String msg, Object object);

        void onFailure(String type, String msg, String arg1);
    }

    public static class LoggingInterceptor implements Interceptor {
        @Override
        public okhttp3.Response intercept(Chain chain) throws IOException {
            //Chain 里包含了request和response
            Request request = chain.request();
            long t1 = System.nanoTime();//请求发起的时间
            okhttp3.Response response = chain.proceed(request);
            long t2 = System.nanoTime();//收到响应的时间
            //不能直接使用response.body（）.string()的方式输出日志
            //因为response.body().string()之后，response中的流会被关闭，程序会报错，
            // 我们需要创建出一个新的response给应用层处理
            ResponseBody responseBody = response.peekBody(1024 * 1024);
            MyLog.showLog(TAG, response.request().url().toString());
            MyLog.showLog(TAG, responseBody.string());
            return response;
        }
    }

    public static class CacheInterceptor implements Interceptor {

        @Override
        public okhttp3.Response intercept(Chain chain) throws IOException {
            Request request = chain.request();
            boolean netAvailable = false;
            if (CheckNetWork.getNetWorkType(MyApp.getMyApp().getApplicationContext()) == CheckNetWork.NETWORKTYPE_INVALID) {
                netAvailable = false;
            } else {
                netAvailable = true;
            }
            if (netAvailable) {
                //网络可用 强制从网络获取数据
                request = request.newBuilder()
                        .cacheControl(CacheControl.FORCE_NETWORK)
                        .build();
            } else {
                //网络不可用 从缓存获取
                request = request.newBuilder()
                        .cacheControl(CacheControl.FORCE_CACHE)
                        .build();
            }

            okhttp3.Response response = chain.proceed(request);

            if (netAvailable) {
                // 有网络时 设置缓存超时时间10分钟
                response = response.newBuilder()
                        .removeHeader("Pragma")
                        .header("Cache-Control", "public, max-age=" + 60 * 10)
                        .build();
            } else {
                // 无网络时，设置超时为1周
                response = response.newBuilder()
                        .removeHeader("Pragma")
                        .header("Cache-Control", "public, only-if-cached, max-stale=" + 7 * 24 * 60 * 60)
                        .build();
            }
            ResponseBody responseBody = response.peekBody(1024 * 1024);
            MyLog.showLog(TAG, response.request().url().toString());
            MyLog.showLog(TAG, responseBody.string());
            return response;
        }
    }

    private static OkHttpClient getOkHttpClient() {
        OkHttpClient.Builder builder = new OkHttpClient.Builder();
        File cacheDir = new File(CacheDataManager.getCachePath(), "response");
        //缓存的最大尺寸10m
        Cache cache = new Cache(cacheDir, 1024 * 1024 * 100);
        builder.cache(cache);
        builder.addInterceptor(new CacheInterceptor());
        builder.connectTimeout(20, TimeUnit.SECONDS);
        builder.readTimeout(20, TimeUnit.SECONDS);
        return builder.build();
    }

    private volatile static GetApi getApi;

    private static GetApi getGetApi() {
        if (getApi == null) {
            synchronized (NetWork.class) {
                if (getApi == null) {
                    MyLog.showLog(TAG, "new Retrofit");
                    Retrofit retrofit = new Retrofit.Builder()
                            .baseUrl(API.BASE_URL)
                            .addConverterFactory(GsonConverterFactory.create())
                            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                            .client(getOkHttpClient())
                            .build();
                    getApi = retrofit.create(GetApi.class);
                }
            }
        }
        return getApi;
    }

    private static void setSuccess(String url, String code, String msg, Object object, CallListener callListener) {
        if (callListener != null) {
            callListener.onSuccess(url, code, msg, object);
        } else {
            MyLog.showLog(TAG, "*****监听器为空****");
        }
    }

    private static void setFailure(String url, Throwable throwable, CallListener callListener) {
        if (callListener != null) {
            MyLog.showLog(TAG, "*****程序异常****" + throwable.toString());
            callListener.onFailure(url, "程序异常" + throwable.toString(), throwable.toString());
        } else {
            MyLog.showLog(TAG, "*****监听器为空****" + throwable.toString());
        }

    }

    //上传
    public static Disposable upLoad(final String url, RequestBody body, final CallListener callListener) {
        return getGetApi().upLoad(url, body)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<ResponseBody>() {
                    @Override
                    public void accept(ResponseBody responseBody) throws Exception {
                        if (responseBody != null) {
                            String result = responseBody.string();
                            JSONObject jsonObject = new JSONObject(result);
                            String code = jsonObject.optString("code");
                            String msg = jsonObject.optString("msg");
                            setSuccess(url, code, msg, null, callListener);
                        }
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        setFailure(url, throwable, callListener);
                    }
                });
    }

    //下载
    public static Disposable downLoad(final String url, final String type, final CallListener callListener) {
        return getGetApi().downLoad(url)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<ResponseBody>() {
                    @Override
                    public void accept(ResponseBody responseBody) throws Exception {
                        if (null != responseBody) {
                            boolean writtenToDisk = writeResponseBodyToDisk(responseBody, url, callListener);
                            if (writtenToDisk) {
                                setSuccess(type, "Y", "下载成功", null, callListener);
                            } else {
                                setSuccess(type, "N", "下载失败", null, callListener);
                            }
                        }
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        setFailure(type, throwable, callListener);
                    }
                });
    }

    //写文件
    public static boolean writeResponseBodyToDisk(ResponseBody body, String url, CallListener callListener) {
        try {

            File futureStudioIconFile = new File(CacheDataManager.getFilePath(), url.substring(url.lastIndexOf("/") + 1));
            if (!futureStudioIconFile.getParentFile().exists()) {
                futureStudioIconFile.getParentFile().mkdirs();
            }
            InputStream inputStream = null;
            OutputStream outputStream = null;
            try {
                byte[] fileReader = new byte[1024];
                long fileSize = body.contentLength();
                long fileSizeDownloaded = 0;
                if (callListener != null) {
                    callListener.onSuccess(API.DOWLOAD_FILE, "D", "进度", null);
                }
                inputStream = body.byteStream();
                outputStream = new FileOutputStream(futureStudioIconFile);
                while (true) {
                    int read = inputStream.read(fileReader);
                    if (read == -1) {
                        break;
                    }
                    outputStream.write(fileReader, 0, read);
                    fileSizeDownloaded += read;
                    if (callListener != null) {
                        callListener.onSuccess(API.DOWLOAD_FILE, "D", "进度", null);
                    }
                }
                outputStream.flush();
                return true;
            } catch (IOException e) {
                return false;
            } finally {
                if (inputStream != null) {
                    inputStream.close();
                }
                if (outputStream != null) {
                    outputStream.close();
                }
            }
        } catch (IOException e) {
            return false;
        }
    }

    //注册
    public static Disposable register(final String url, final Map<String, String> map, final CallListener callListener) {
        return getGetApi().register(url, map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<String>() {
                    @Override
                    public void accept(String registerBean) throws Exception {
                        setSuccess(url, "", "", registerBean, callListener);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        setFailure(url, throwable, callListener);
                    }
                });

    }

    //登录
    public static Disposable login(final String url, final Map<String, String> map, final CallListener callListener) {
        return getGetApi().login(url, map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<LoginBean>() {
                    @Override
                    public void accept(LoginBean loginBean) throws Exception {
                        setSuccess(url, loginBean.getCode(), loginBean.getMsg(), loginBean, callListener);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        setFailure(url, throwable, callListener);
                    }
                });
    }

    //基本资料
    public static Disposable getbasicinfo(final String url, final Map<String, String> map, final CallListener callListener){
        return getGetApi().getbasicinfo(url, map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<LoginBean>() {
                    @Override
                    public void accept(LoginBean loginBean) throws Exception {
                        setSuccess(url, loginBean.getCode(), loginBean.getMsg(), loginBean, callListener);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        setFailure(url, throwable, callListener);
                    }
                });
    }

    //统计信息
    public static Disposable getapptjlist(final String url, final Map<String, String> map, final CallListener callListener) {
        return getGetApi().getapptjlist(url, map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<AppTJListBean>() {
                    @Override
                    public void accept(AppTJListBean appTJListBean) throws Exception {
                        setSuccess(url, appTJListBean.getCode(), appTJListBean.getMsg(), appTJListBean, callListener);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        setFailure(url, throwable, callListener);
                    }
                });
    }

    //常用资料
    public static Disposable getsyappzllist(final String url, final Map<String, String> map, final CallListener callListener) {
        return getGetApi().getsyappzllist(url, map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<AppZLListBean>() {
                    @Override
                    public void accept(AppZLListBean loginBean) throws Exception {
                        setSuccess(url, loginBean.getCode(), loginBean.getMsg(), loginBean, callListener);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        setFailure(url, throwable, callListener);
                    }
                });
    }

    //更多资料
    public static Disposable getappsyzlgdlist(final String url, final Map<String, String> map, final CallListener callListener) {
        return getGetApi().getappsyzlgdlist(url, map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<AppZLListBean>() {
                    @Override
                    public void accept(AppZLListBean loginBean) throws Exception {
                        setSuccess(url, loginBean.getCode(), loginBean.getMsg(), loginBean, callListener);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        setFailure(url, throwable, callListener);
                    }
                });
    }

    //通讯录
    public static Disposable gettxllist(final String url, final Map<String, String> map, final CallListener callListener) {
        return getGetApi().gettxllist(url, map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<TXLBean>() {
                    @Override
                    public void accept(TXLBean loginBean) throws Exception {
                        setSuccess(url, loginBean.getCode(), loginBean.getMsg(), loginBean, callListener);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        setFailure(url, throwable, callListener);
                    }
                });
    }

    //版本更新
    public static Disposable getversioninfo(final String url, final Map<String, String> map, final CallListener callListener) {
        return getGetApi().getversioninfo(url, map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<VersionBean>() {
                    @Override
                    public void accept(VersionBean loginBean) throws Exception {
                        setSuccess(url, loginBean.getCode(), loginBean.getMsg(), loginBean, callListener);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        setFailure(url, throwable, callListener);
                    }
                });
    }

    //组别选择
    public static Disposable getappzlgrouplist(final String url, final Map<String, String> map, final CallListener callListener) {
        return getGetApi().getappzlgrouplist(url, map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<AppZLGroupBean>() {
                    @Override
                    public void accept(AppZLGroupBean loginBean) throws Exception {
                        setSuccess(url, loginBean.getCode(), loginBean.getMsg(), loginBean, callListener);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        setFailure(url, throwable, callListener);
                    }
                });
    }

    //业务--沟通计划
    public static Disposable getywgtjhlist(final String url, final Map<String, String> map, final CallListener callListener) {
        return getGetApi().getywgtjhlist(url, map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<YWgtjhBean>() {
                    @Override
                    public void accept(YWgtjhBean loginBean) throws Exception {
                        setSuccess(url, loginBean.getCode(), loginBean.getMsg(), loginBean, callListener);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        setFailure(url, throwable, callListener);
                    }
                });
    }

    //业务--沟通日志
    public static Disposable getywgtrzlist(final String url, final Map<String, String> map, final CallListener callListener) {
        return getGetApi().getywgtrzlist(url, map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<YWgtjhBean>() {
                    @Override
                    public void accept(YWgtjhBean loginBean) throws Exception {
                        setSuccess(url, loginBean.getCode(), loginBean.getMsg(), loginBean, callListener);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        setFailure(url, throwable, callListener);
                    }
                });
    }

    //客户--基本资料
    public static Disposable getkhzlinfo(final String url, final Map<String, String> map, final CallListener callListener) {
        return getGetApi().getkhzlinfo(url, map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<CustomerBean>() {
                    @Override
                    public void accept(CustomerBean loginBean) throws Exception {
                        setSuccess(url, loginBean.getCode(), loginBean.getMsg(), loginBean, callListener);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        setFailure(url, throwable, callListener);
                    }
                });
    }

    //客户--沟通计划
    public static Disposable getzlgtplanlist(final String url, final Map<String, String> map, final CallListener callListener) {
        return getGetApi().getzlgtplanlist(url, map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<YWgtjhBean>() {
                    @Override
                    public void accept(YWgtjhBean loginBean) throws Exception {
                        setSuccess(url, loginBean.getCode(), loginBean.getMsg(), loginBean, callListener);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        setFailure(url, throwable, callListener);
                    }
                });
    }

    //客户--沟通日志
    public static Disposable getkhzlgtrzlist(final String url, final Map<String, String> map, final CallListener callListener) {
        return getGetApi().getkhzlgtrzlist(url, map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<YWgtjhBean>() {
                    @Override
                    public void accept(YWgtjhBean loginBean) throws Exception {
                        setSuccess(url, loginBean.getCode(), loginBean.getMsg(), loginBean, callListener);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        setFailure(url, throwable, callListener);
                    }
                });
    }

    //首页--排行榜
    public static Disposable getRankList(final String url, final Map<String, String> map, final CallListener callListener) {
        return getGetApi().getRankList(url, map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<RankListBean>() {
                    @Override
                    public void accept(RankListBean rankListBean) throws Exception {
                        setSuccess(url, rankListBean.getCode(), rankListBean.getMsg(), rankListBean, callListener);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        setFailure(url, throwable, callListener);
                    }
                });
    }

    //资料--任务完成与取消
    public static Disposable saverwflaginfo(final String url, final Map<String, String> map, final CallListener callListener) {
        return getGetApi().saverwflaginfo(url, map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<RankListBean>() {
                    @Override
                    public void accept(RankListBean rankListBean) throws Exception {
                        setSuccess(url, rankListBean.getCode(), rankListBean.getMsg(), rankListBean, callListener);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        setFailure(url, throwable, callListener);
                    }
                });
    }

    //客户--沟通日志快捷方式
    public static Disposable getgtkjlist(final String url, final Map<String, String> map, final CallListener callListener) {
        return getGetApi().getgtkjlist(url, map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<GTKJListBean>() {
                    @Override
                    public void accept(GTKJListBean rankListBean) throws Exception {
                        setSuccess(url, rankListBean.getCode(), rankListBean.getMsg(), rankListBean, callListener);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        setFailure(url, throwable, callListener);
                    }
                });
    }

    //客户--新增沟通日志
    public static Disposable savenewgtrzinfo(final String url, final Map<String, String> map, final CallListener callListener) {
        return getGetApi().savenewgtrzinfo(url, map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<GTKJListBean>() {
                    @Override
                    public void accept(GTKJListBean rankListBean) throws Exception {
                        setSuccess(url, rankListBean.getCode(), rankListBean.getMsg(), rankListBean, callListener);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        setFailure(url, throwable, callListener);
                    }
                });
    }

    //客户--删除沟通日志
    public static Disposable savedelgtrzinfo(final String url, final Map<String, String> map, final CallListener callListener) {
        return getGetApi().savedelgtrzinfo(url, map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<GTKJListBean>() {
                    @Override
                    public void accept(GTKJListBean rankListBean) throws Exception {
                        setSuccess(url, rankListBean.getCode(), rankListBean.getMsg(), rankListBean, callListener);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        setFailure(url, throwable, callListener);
                    }
                });
    }

    //客户--保存沟通计划
    public static Disposable savegtpalninf(final String url, final Map<String, String> map, final CallListener callListener) {
        return getGetApi().savegtpalninf(url, map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<GTKJListBean>() {
                    @Override
                    public void accept(GTKJListBean rankListBean) throws Exception {
                        setSuccess(url, rankListBean.getCode(), rankListBean.getMsg(), rankListBean, callListener);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        setFailure(url, throwable, callListener);
                    }
                });
    }

    //客户--沟通详情
    public static Disposable getgtjhinfo(final String url, final Map<String, String> map, final CallListener callListener) {
        return getGetApi().getgtjhinfo(url, map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<PlanInfoBean>() {
                    @Override
                    public void accept(PlanInfoBean rankListBean) throws Exception {
                        setSuccess(url, rankListBean.getCode(), rankListBean.getMsg(), rankListBean, callListener);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        setFailure(url, throwable, callListener);
                    }
                });
    }

    //资料--分享
    public static Disposable savefxinfo(final String url, final Map<String, String> map, final CallListener callListener) {
        return getGetApi().savefxinfo(url, map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<PlanInfoBean>() {
                    @Override
                    public void accept(PlanInfoBean rankListBean) throws Exception {
                        setSuccess(url, rankListBean.getCode(), rankListBean.getMsg(), rankListBean, callListener);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        setFailure(url, throwable, callListener);
                    }
                });
    }

    //签到
    public static Disposable saveqdinfo(final String url, final Map<String, String> map, final CallListener callListener) {
        return getGetApi().saveqdinfo(url, map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<PlanInfoBean>() {
                    @Override
                    public void accept(PlanInfoBean rankListBean) throws Exception {
                        setSuccess(url, rankListBean.getCode(), rankListBean.getMsg(), rankListBean, callListener);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        setFailure(url, throwable, callListener);
                    }
                });
    }


}
